/*
 * GccApplication1.c
 *
 * Created: 4/21/2015 10:22:55 AM
 *  Author: schussle
 */ 


#include <util/delay.h>
#define F_CPU 8000000UL //XTAL = 1 MHz
#include <avr/io.h>
int main ()
{
	while (1) //wait here forever after dimming is done
	{
		
		unsigned char i;
		unsigned char j;
		unsigned char k;
		
		DDRB = 0xFF; //PB3 as output
		i = 230;
		j=0;
		OCR1A = 230; //duty cycle = 50%
		TCCR1A = 0xC1; //Phase Correct PWM, inverted, N = 64
		TCCR1B = 0x03;
		OCR2A = 230; //duty cycle = 50%
		TCCR2A = 0xC1; //Phase Correct PWM, inverted, N = 64
		TCCR2B = 0x03;
		OCR0A = 127; //duty cycle = 50%
		TCCR0A = 0xC1;
		TCCR0B = 0x03;
		while (i != 0 )
		{
			OCR1A = i;
			_delay_ms(25); //use AVR studio library delay
			while (j !=230)
			{
				OCR2A = j;
				_delay_ms(25);
				
				j++;
			}
			i--;
			
		}

		
		DDRB = 0x02; //PB3 as output
		DDRD = 0xff;
		i = 230;
		k=0;
		OCR1A = 230; //duty cycle = 50%
		TCCR1A = 0xC1; //Phase Correct PWM, inverted, N = 64
		TCCR1B = 0x03;
		OCR2A = 230; //duty cycle = 50%
		TCCR2A = 0xC1; //Phase Correct PWM, inverted, N = 64
		TCCR2B = 0x03;
		OCR0A = 230; //duty cycle = 50%
		TCCR0A = 0xC1;
		TCCR0B = 0x03;
		while (i != 0 )
		{
			OCR1A = i;
			_delay_ms(25); //use AVR studio library delay
			while (k !=230)
			{
				OCR0A = k;
				_delay_ms(25);
				
				k++;
			}
			i--;
			
		}
		
		
		DDRB = 0x04; //PB3 as output
		DDRD = 0xff;
		i = 230;
		k=0;
		OCR1A = 230; //duty cycle = 50%
		TCCR1A = 0xC1; //Phase Correct PWM, inverted, N = 64
		TCCR1B = 0x03;
		OCR2A = 230; //duty cycle = 50%
		TCCR2A = 0xC1; //Phase Correct PWM, inverted, N = 64
		TCCR2B = 0x03;
		OCR0A = 230; //duty cycle = 50%
		TCCR0A = 0xC1;
		TCCR0B = 0x03;
		while (i != 0 )
		{
			OCR0A = i;
			_delay_ms(25); //use AVR studio library delay
			while (k !=230)
			{
				OCR2A = k;
				_delay_ms(25);
				
				k++;
			}
			i--;
			
		}

		
		
		DDRB = 0xFF; //PB3 as output
		i = 230;
		j=0;
		OCR1A = 230; //duty cycle = 50%
		TCCR1A = 0xC1; //Phase Correct PWM, inverted, N = 64
		TCCR1B = 0x03;
		OCR2A = 230; //duty cycle = 50%
		TCCR2A = 0xC1; //Phase Correct PWM, inverted, N = 64
		TCCR2B = 0x03;
		OCR0A = 127; //duty cycle = 50%
		TCCR0A = 0xC1;
		TCCR0B = 0x03;
		while (i != 0 )
		{
			OCR2A = i;
			_delay_ms(25); //use AVR studio library delay
			while (j !=230)
			{
				OCR1A = j;
				_delay_ms(25);
				
				j++;
			}
			i--;
			
		}
		
		
		
		
		
		
		DDRB = 0x02; //PB3 as output
		DDRD = 0xff;
		i = 230;
		k=0;
		OCR1A = 230; //duty cycle = 50%
		TCCR1A = 0xC1; //Phase Correct PWM, inverted, N = 64
		TCCR1B = 0x03;
		OCR2A = 230; //duty cycle = 50%
		TCCR2A = 0xC1; //Phase Correct PWM, inverted, N = 64
		TCCR2B = 0x03;
		OCR0A = 230; //duty cycle = 50%
		TCCR0A = 0xC1;
		TCCR0B = 0x03;
		while (i != 0 )
		{
			OCR0A = i;
			_delay_ms(25); //use AVR studio library delay
			while (k !=230)
			{
				OCR1A = k;
				_delay_ms(25);
				
				k++;
			}
			i--;
			
		}
		
		
		DDRB = 0x04; //PB3 as output
		DDRD = 0xff;
		i = 230;
		k=0;
		OCR1A = 230; //duty cycle = 50%
		TCCR1A = 0xC1; //Phase Correct PWM, inverted, N = 64
		TCCR1B = 0x03;
		OCR2A = 230; //duty cycle = 50%
		TCCR2A = 0xC1; //Phase Correct PWM, inverted, N = 64
		TCCR2B = 0x03;
		OCR0A = 230; //duty cycle = 50%
		TCCR0A = 0xC1;
		TCCR0B = 0x03;
		while (i != 0 )
		{
			OCR2A = i;
			_delay_ms(25); //use AVR studio library delay
			while (k !=230)
			{
				OCR0A = k;
				_delay_ms(25);
				
				k++;
			}
			i--;
			
		}
		
	}
	return 0;
}